#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>

void handler(int signo)
{
  pid_t id;
  while((id = waitpid(-1, NULL, WNOHANG)) > 0)
  {
    printf("wait child successfully! chlid pid:%d\n", id);   
  }
  printf("child quit successfully!\n");
}

int main()
{
  signal(SIGCHLD, handler);
  
  int fd = fork();
  if(fd < 0){
    perror("fork");
    return 1;
  }

  if(fd == 0){
    printf("I am child\n");
    sleep(5);
    exit(0);
  }

  printf("I am father\n");
  sleep(7);

  return 0;
}
